#include <math.h>

#include "CylinderedModule.h"
CylinderedModule::CylinderedModule(): maxY(0), minY(0), radius(0){

}
float CylinderedModule::absoluteValue(float f){
    if (f < 0.0)
        return -f;
    return f;
}
float CylinderedModule::getRadius(){
    return radius;
}
float CylinderedModule::getMaxY(){
    return maxY;
}
float CylinderedModule::getMinY(){
    return minY;
}
void CylinderedModule::setCylValues(std::vector<Triangle> triangles, float X, float Y, float Z){
    float maximumY = 0,
          minimumY = 40.0,
          rad      = 0,
          newRad   = 0,
          currentY  = 0;
    Triangle tr;
    for (unsigned int i = 0; i < triangles.size(); i++) {
        tr = triangles[i];
        for (int j = 0; j < 3; j++) {
            newRad = sqrtf((tr.vertex[j].x - X)*(tr.vertex[j].x - X) + (tr.vertex[j].z - Z)*(tr.vertex[j].z - Z));
            currentY = tr.vertex[j].y - Y;

            // set possible new values
            if (currentY > maximumY)
                maximumY = currentY;
            if (currentY < minimumY)
                minimumY = currentY;
            if (newRad > rad)
                rad = newRad;
        }
        //triangles.pop_back();
    }
    radius = rad;
    maxY = maximumY;
    minY = minimumY;
    
}
